#include "pch.h"
#include "clogger.h"

CLogger::CLogger()
{
    fileSink_ = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("logger/librtsp.log", 5 * 1024 * 1024, 100);
    fileSink_->set_pattern("[%Y-%m-%d %H:%M:%S.%e][%t][%^%l%$] %v");
    consoleSink_ = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
    consoleSink_->set_pattern("[%H:%M:%S.%e][%t][%^%l%$] %v");
    spdlog::set_default_logger(std::make_shared<spdlog::logger>("librtsp", spdlog::sinks_init_list{ fileSink_ }));
    spdlog::set_level(spdlog::level::trace);
    spdlog::flush_on(spdlog::level::debug);
}

CLogger::~CLogger()
{
    spdlog::shutdown();
}

void CLogger::EnableConsole()
{
    spdlog::set_default_logger(std::make_shared<spdlog::logger>("librtsp", spdlog::sinks_init_list{ fileSink_, consoleSink_ }));
    spdlog::set_level(spdlog::level::trace);
    spdlog::flush_on(spdlog::level::debug);
}